//
//  AXMySrdzWdJsCell.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/8.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXMySrdzWdJsCell.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "UITableView+SDAutoTableViewCellHeight.h"


@implementation AXMySrdzWdJsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self creatView];
        [self setlayout];
    }
    return self;
}




- (void)creatView {
    
    
    /**  uiview */
    self.bgView = [[UIView alloc]init];
    self.bgView.cornerRadius = 5;
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bgView];
    
    /** title */
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.textColor = COLOR_DIV;
    self.titleLabel.font = FONT_FOURTEEN;;
    [self.bgView addSubview:self.titleLabel];
    /**  price */
    self.priceLabel = [[UILabel alloc]init];
    
    self.priceLabel.textColor = COLOR_ORG;
    self.priceLabel.font = FONT_FOURTEEN;;
    [self.bgView addSubview:self.priceLabel];
    /**  content */
    self.contentLabel = [[UILabel alloc]init];
    self.contentLabel.textColor = COLOR_Gray;
    self.contentLabel.font = FONT_FOURTEEN;;
    [self.bgView addSubview:self.contentLabel];
    
    /** line */
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.bgView addSubview:self.lineView];
    
    /** name  */
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.textColor = COLOR_Gray;
    self.nameLabel.font = FONT_FOURTEEN;;
    [self.bgView addSubview:self.nameLabel];
    /**  crop*/
    self.cropLabel = [[UILabel alloc]init];
    
    self.cropLabel.textColor = COLOR_Gray;
    self.cropLabel.font = FONT_FOURTEEN;;
    [self.bgView addSubview:self.cropLabel];
    /** more */
    self.moreBtn = [[UIButton alloc]init];
    self.moreBtn.titleLabel.font = FONT_FOURTEEN;
    [self.moreBtn setTitleColor:COLOR_GREEN forState:UIControlStateNormal];
    [self.moreBtn setTitle:@"查看更多" forState:UIControlStateNormal];
    [self.moreBtn addTarget:self action:@selector(more:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.moreBtn];
}


- (void)setModel:(AXMySrdzWdJsModel *)model {
    _model=model;
    self.titleLabel.text = [NSString stringWithFormat:@"%@",model.fStrategyName];
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",model.fPrice];
    
    self.contentLabel.text = [NSString stringWithFormat:@"诊断结论：%@",model.fDiagnosisStrategy];
    
    self.nameLabel.text = [NSString stringWithFormat:@"专家：%@",model.fExpertName];
    
    self.cropLabel.text = [NSString stringWithFormat:@"作物：%@",model.fCropName];
    
}


- (void)setlayout {
    
    
    
    /**  uiview */
    self.bgView.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 5)
    .widthIs(SCREEN_WIDTH - 20)
    .autoHeightRatio(0)
    .minHeightIs(131);
    
    /**  price */
    self.priceLabel.sd_layout
    .rightSpaceToView(self.bgView, 10)
    .topSpaceToView(self.bgView, 10)
    .widthIs(80)
    .heightIs(20);
    
    /** title */
    self.titleLabel.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.bgView, 10)
    .rightSpaceToView(self.priceLabel, 10)
    .heightIs(20);
    
    /**  content */
    self.contentLabel.sd_layout
    .leftEqualToView(self.titleLabel)
    .topSpaceToView(self.titleLabel, 10)
    .widthIs(SCREEN_WIDTH-40)
    .autoHeightRatio(0)
    .minHeightIs(40);
    
    self.lineView.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.contentLabel, 10)
    .widthIs(SCREEN_WIDTH-40)
    .heightIs(1);
    
    /** name  */
    self.nameLabel.sd_layout
    .leftEqualToView(self.titleLabel)
    .topSpaceToView(self.lineView, 10)
    .widthIs(100)
    .heightRatioToView(self.titleLabel, 1);
    
    /**  crop*/
    self.cropLabel.sd_layout
    .leftSpaceToView(self.nameLabel, 10)
    .topSpaceToView(self.lineView, 10)
    .widthIs(100)
    .heightRatioToView(self.titleLabel, 1);
    /** more */
    
    self.moreBtn.sd_layout
    .rightSpaceToView(self.bgView, 10)
    .topSpaceToView(self.lineView, 10)
    .widthIs(60)
    .heightRatioToView(self.titleLabel, 1);
    
    
    /** cell 自适应第一步 */
    [self setupAutoHeightWithBottomView:self.bgView bottomMargin:10];
    
}


#pragma mark = action

- (void)more:(UIButton * )btn {
    
    
    if (self.tapCelllickedBlock) {
        
        self.tapCelllickedBlock(btn.tag);
    }
}

@end


